03. Video + Quiz: Write Your First Subquery
Your First Subquery
Your First Subquery
The first time you write a subquery it might seem really complex. Let's try breaking it down into its different parts.
If you get stuck look again at the video above. We want to find the average number of events for each day for each channel. The first table will provide us the number of events for each day and channel, and then we will need to average these values together using a second query.
You try solving this yourself.
Task Description:
Tasks to complete.
Task Feedback:
Nice job! Understanding how to nest one query within another query is key to answering many questions that pertain to any company storing data in a relational database.
Code
If you need a code on the https://github.com/udacity.
SOLUTION:
- January 1, 2017; direct
- December 21, 2016; direct
SOLUTION:
- The original query goes in the **FROM** statement.
- An `*` is used in the **SELECT** statement to pull all of the data from the original query.
- You **MUST** use an alias for the table you nest within the outer query.
QUIZ QUESTION::
Match each channel to its corresponding average number of events per day.
ANSWER CHOICES:
Channel |
Average Number of Events/Day |
---|---|
direct |
|
organic |
|
SOLUTION:
Channel |
Average Number of Events/Day |
---|---|
organic |
|
|
|
|
|
direct |